package com.girlbook.page;

/**
 * 分页显示对象
 * 
 * @param
 */
public class PageView
{
	/** 页码开始索引和结束索引 **/
	private PageIndex pageIndex;
	/** 总页数 **/
	private long totalPage = 1;
	/** 每页显示记录数 **/
	private int maxResult = 10;
	/** 当前页 **/
	private int currentPage = 1;
	/** 总记录数 **/
	private long totalRecord;
	/** 页码数量 **/
	private int pageCount = 5;
	
	/**
	 * currentIndex为当前索引,(当前页码-1)*每页记录数
	 */
	public PageView(int maxResult, int currentIndex, long totalRecord, int pageCount)
	{
		this.maxResult = maxResult;
		this.currentPage = totalRecord == 0 ? 0 : (int) Math.ceil((float) currentIndex / (float) maxResult);
		this.pageCount = pageCount;
		setTotalRecord(totalRecord);
	}

	public PageView()
	{
	}

	public void setParams(int maxResult, int currentPage, long totalRecord, int pageCount)
	{
		this.setMaxResult(maxResult);
		this.setCurrentPage(currentPage);
		this.setTotalRecord(totalRecord);
		this.setPageCount(pageCount);
	}


	/** 要获取记录的开始索引 **/
	public int getFirstResult()
	{
		return (this.currentPage - 1) * this.maxResult;

	}

	public long getTotalRecord()
	{
		return totalRecord;
	}

	public void setTotalRecord(long totalRecord)
	{
		this.totalRecord = totalRecord;
		setTotalPage(this.totalRecord % this.maxResult == 0 ? this.totalRecord
				/ this.maxResult : this.totalRecord / this.maxResult + 1);
	}

	public PageIndex getPageIndex()
	{
		return pageIndex;
	}

	public long getTotalPage()
	{
		return totalPage;
	}

	public void setTotalPage(long totalpage)
	{
		this.totalPage = totalpage;
		this.pageIndex = PageIndex.getPageIndex(pageCount, currentPage, totalpage);
	}

	/**
	 * 每页显示记录数
	 * 
	 * @return
	 */
	public int getMaxResult()
	{
		return maxResult;
	}

	public int getCurrentPage()
	{
		return currentPage;
	}

	public void setMaxResult(int maxResult)
	{
		this.maxResult = maxResult;
	}

	public void setCurrentPage(int currentPage)
	{
		this.currentPage = currentPage;
	}

	public int getPageCount()
	{
		return pageCount;
	}

	public void setPageCount(int pageCount)
	{
		this.pageCount = pageCount;
	}

}